import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { BaseService } from './base.service';
import { User } from '../domain/user';
import { MgUser } from '../domain/mguser';
import { MD5 } from '../common/md5';
import { CircleFriend } from '../domain/circleFriend';

@Injectable()
export class UserService extends BaseService {
    constructor(protected http: Http) {
        super();
    }

    GetUserList(params?: UserQueryParameter) {
        let url = "manager/get_user_list";
        return this.Post<{ count: number, list: User[] }>(url, params);
    }

    GetUserInfo(userId: number) {
        let url = "manager/find_id";
        return this.Post<User>(url, { userid: userId });
    }

    DisableUser(userId: number) {
        let url = "manager/disableUser";
        return this.Post(url, { userid: userId });
    }

    EnableUser(userId: number) {
        let url = "manager/enableUser";
        return this.Post(url, { userid: userId });
    }

    GetManageUserList(params: UserQueryParameter) {
        let url = "manager/getMgUsers";
        return this.Post<{ count: number, list: MgUser[] }>(url, params);
    }

    GetMgUserInfo(id: number) {
        let url = "manager/getMgUserInfo";

        return this.Post<MgUser>(url, { mangerId: id });
    }

    DeleteMgUser(id: number) {
        let url = "manager/delMgUser";
        return this.Post(url, { mangerId: id });
    }

    SaveMgUser(mguser: MgUser) {
        let url = "manager/saveMgUser";
        mguser.password = MD5.getHashCode(mguser.password);
        return this.Post(url, mguser);
    }

    UpdateMgUserPassword(id: number, password: string) {
        let url = "manager/updateMgPassword";
        return this.Post(url, { mangerId: id, password: password });
    }

    GetCircleFriendList(params: BaseQueryParameter) {
        let url = "manager/circle_item_list";
        return this.Post<{ count: number; list: CircleFriend[] }>(url, params);
    }

    GetCircleFriendInfo(id: number) {
        let url = "manager/circle_item_info";
        return this.Post(url, { itemId: id });
    }

    VerifyCircle(id: number, status: number) {
        let url = "manager/verify_circle";
        return this.Post(url, { itemId: id, status: status });
    }
}

export interface UserQueryParameter extends BaseQueryParameter {
    userNick?: string;
    phone?: string;
    userStatus?: number;
    loginName?: string;
}

export interface BaseQueryParameter {
    currentPage?: number;
    pageSize?: number;
}